#pragma once

#include <QObject>
#include <qthread.h>
#include <vector>
#include <opencv2/opencv.hpp>

#define DEFAULT_ADJUST_THRESHOLD 0.4

class QtMatchThread  : public QThread
{
	Q_OBJECT
public:
	QtMatchThread(QObject *parent = NULL);
	QtMatchThread(std::vector<cv::Mat>srcMatParams, std::vector<cv::Mat>templateMatParams, float scale_step, int rotate_step, int poolSize, QObject *parent = NULL);
	void setParams(std::vector<cv::Mat>srcMatParams, std::vector<cv::Mat>templateMatParams, float scale_step, int rotate_step, int poolSize);
	void setAdjust(float threshold = DEFAULT_ADJUST_THRESHOLD);

	int OUTCURVE_DST = 3;
	int OUTCURVE_WIDTH = 1;
	int closeElememtSize = 15;
	int MIN_CONNECTAREA = 5000;

private:
	

	cv::Mat src;
	cv::Mat srcGrayMat;
	cv::Mat srcBinMat;
	cv::Mat srcOutCurve;
	cv::Mat srcOutCurveMask;

	cv::Mat template_curve;
	cv::Mat outsideCurve;
	cv::Mat outsideCurveMask;

	std::vector<cv::Mat>searchROIs;
	std::vector <cv::Point> ROIStartPoints;
	//std::vector<cv::Mat>srcCrop;
	float scale_step = 0.1;
	int rotate_step = 3;
	int poolSize = 15;
	std::map<std::pair<float, float>, cv::Mat>prymid;
	const float degreeRangeLength = 180.0;
	bool adjust = false;
	float ADJUST_CURVE_THRESHOLD = DEFAULT_ADJUST_THRESHOLD;
protected:
	void run();
signals:
	void FinishMatching(cv::Mat* resault);
	void FinishMatching();
	void UpdateMatchStatus(int status_code, int param = 0);
};
